<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
<style type="text/css">
	ul{
		margin-left:25;padding:0;
 		list-style:none; 
	}
	.mini-checkboxlist-item{
		padding: 10px;
	}
	.Edit_Button, .Delete_Button, .Update_Button, .Cancel_Button
    {
        font-size:11px;color:#1B3F91;font-family:Verdana;  
        margin-right:5px;
    }
    .mini-radiobuttonlist-td
    {
    	height: 25px;
    }
</style>
</head>
<body>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
	            <td style="width:100%;">
	            	<sec:authorize url='/customer_recommend_add.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="addRecommend()" plain="true">增加</a>
	                </sec:authorize>
	            </td>
	        </tr>
	    </table>           
   	</div>
	<div id="datagrid1" class="mini-datagrid" showPager="false" onlyCheckSelection="true" idField="id" allowCellWrap="true" url="customer_recommend_view.do" style="width:100%;height:auto;">
		<div property="columns">
			<div type="indexcolumn" width="15"></div>
			<div field="serialNum" width="50" headerAlign="center" align="center">客户编号</div>
			<div field="name" width="50" headerAlign="center" align="left">客户姓名</div>
			<div field="contactNo" width="50" headerAlign="center" align="center">电话</div>
			<div field="createTime" width="70" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss">记录时间</div>
			<div header="地址" headerAlign="center">
				<div property="columns">
					<div field="pName" width="50" headerAlign="center" align="center" >省</div>
					<div field="cName" width="50" headerAlign="center" align="center" >市</div>
					<div field="dName" width="50" headerAlign="center" align="center" >区</div>
					<div field="address" width="50" headerAlign="center" align="center" >详细地址</div>
				</div>
			</div>
			<sec:authorize url='/customer_recommend_edit.do'>
			<div field="pocessingStatus" width="50" headerAlign="center" renderer="openCustomer" align="center">相关操作</div>
			</sec:authorize>
		</div>
	</div>
	<input class="mini-hidden" id="recommend_id"/>
	<input class="mini-hidden" id="recommend_name"/>
	
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	var recommendId = mini.get("recommend_id");
	var recommendName = mini.get("recommend_name");
	function SetData(data) {
		data = mini.clone(data);
		recommendId.setValue(data.customerId);
		recommendName.setValue(data.customerName);
		grid.load({id: data.customerId});
	}
	
	// 打开客户信息
	function openCustomer(e) {
		var record = e.record;
		return '<a href="javascript: loadCustomer('+record._uid+');">打开客户信息</a>';
	}
	
	// 加载推荐客户信息
	function loadCustomer(row_uid) {
		var row = grid.getRowByUID(row_uid);
		mini.open({
            url: "customer_recommend_edit.do",
            title: "打开客户信息", width: 800, height: 600,
            allowResize: false,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { row: row, recommendName: recommendName.getValue() };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
            	grid.reload();
            }
        });
	}
	
	// 打开添加推荐客户页面
	function addRecommend() {
		mini.open({
            url: "customer_recommend_add.do",
            title: "添加推荐客户", width: 800, height: 600,
            allowResize: false,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { recommendId: recommendId.getValue(), recommendName: recommendName.getValue() };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
            	if(action.close == "close") {
	            	$.post("customer_recommend_del.do", {id: action.customerId, callId: action.callId}, function(data){
	            		if(!data.success){
	            			mini.alert("删除推荐信息错误！");
	            		}
		           		grid.reload();
	            	}, "json");
            	} else {
            		grid.reload();
            	}
            }
        });
	}

</script>
</body>
</html>